<template>
  <el-dialog
    :title="!dataForm.buildId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="地区ID" prop="areaId">
      <el-input v-model="dataForm.areaId" placeholder="地区ID"></el-input>
    </el-form-item>
    <el-form-item label="楼盘名称" prop="buildName">
      <el-input v-model="dataForm.buildName" placeholder="楼盘名称"></el-input>
    </el-form-item>
    <el-form-item label="均价" prop="buildPrice">
      <el-input v-model="dataForm.buildPrice" placeholder="均价"></el-input>
    </el-form-item>
    <el-form-item label="楼盘地址" prop="buildAddress">
      <el-input v-model="dataForm.buildAddress" placeholder="楼盘地址"></el-input>
    </el-form-item>
    <el-form-item label="售楼处地址" prop="buildSellAddress">
      <el-input v-model="dataForm.buildSellAddress" placeholder="售楼处地址"></el-input>
    </el-form-item>
    <el-form-item label="开盘时间" prop="buildStartTime">
      <el-input v-model="dataForm.buildStartTime" placeholder="开盘时间"></el-input>
    </el-form-item>
    <el-form-item label="交房时间" prop="buildEndTime">
      <el-input v-model="dataForm.buildEndTime" placeholder="交房时间"></el-input>
    </el-form-item>
    <el-form-item label="售楼电话" prop="buildSellTel">
      <el-input v-model="dataForm.buildSellTel" placeholder="售楼电话"></el-input>
    </el-form-item>
    <el-form-item label="预售证号" prop="buildSellCard">
      <el-input v-model="dataForm.buildSellCard" placeholder="预售证号"></el-input>
    </el-form-item>
    <el-form-item label="开发商ID" prop="developerId">
      <el-input v-model="dataForm.developerId" placeholder="开发商ID"></el-input>
    </el-form-item>
    <el-form-item label="地图坐标" prop="areaAxis">
      <el-input v-model="dataForm.areaAxis" placeholder="地图坐标"></el-input>
    </el-form-item>
    <el-form-item label="是否优惠楼盘(0 - 否 1- 是)" prop="buildSpecial">
      <el-input v-model="dataForm.buildSpecial" placeholder="是否优惠楼盘(0 - 否 1- 是)"></el-input>
    </el-form-item>
    <el-form-item label="装修情况(  0 - 毛坯 1 - 简装 2 - 精装 3- 豪装)" prop="buildFitment">
      <el-input v-model="dataForm.buildFitment" placeholder="装修情况(  0 - 毛坯 1 - 简装 2 - 精装 3- 豪装)"></el-input>
    </el-form-item>
    <el-form-item label="销售状态(0 - 在售 1- 新盘 2- 尾盘 3- 售罄 4-未开盘)" prop="buildSellType">
      <el-input v-model="dataForm.buildSellType" placeholder="销售状态(0 - 在售 1- 新盘 2- 尾盘 3- 售罄 4-未开盘)"></el-input>
    </el-form-item>
    <el-form-item label="楼盘类型(1-住宅 2-别墅 3-商铺 4-写字楼 5-公寓 6-底盘)" prop="buildType">
      <el-input v-model="dataForm.buildType" placeholder="楼盘类型(1-住宅 2-别墅 3-商铺 4-写字楼 5-公寓 6-底盘)"></el-input>
    </el-form-item>
    <el-form-item label="缩略图" prop="buildPng">
      <el-input v-model="dataForm.buildPng" placeholder="缩略图"></el-input>
    </el-form-item>
    <el-form-item label="看房视频" prop="buildVideo">
      <el-input v-model="dataForm.buildVideo" placeholder="看房视频"></el-input>
    </el-form-item>
    <el-form-item label="vr看房" prop="buildVr">
      <el-input v-model="dataForm.buildVr" placeholder="vr看房"></el-input>
    </el-form-item>
    <el-form-item label="楼盘介绍" prop="buildIntroduce">
      <el-input v-model="dataForm.buildIntroduce" placeholder="楼盘介绍"></el-input>
    </el-form-item>
    <el-form-item label="产权年限" prop="buildPropertyright">
      <el-input v-model="dataForm.buildPropertyright" placeholder="产权年限"></el-input>
    </el-form-item>
    <el-form-item label="占地面积" prop="buildFloorspace">
      <el-input v-model="dataForm.buildFloorspace" placeholder="占地面积"></el-input>
    </el-form-item>
    <el-form-item label="建筑面积" prop="buildBuildspace">
      <el-input v-model="dataForm.buildBuildspace" placeholder="建筑面积"></el-input>
    </el-form-item>
    <el-form-item label="容积率" prop="buildPlotratio">
      <el-input v-model="dataForm.buildPlotratio" placeholder="容积率"></el-input>
    </el-form-item>
    <el-form-item label="绿化率" prop="buildGreen">
      <el-input v-model="dataForm.buildGreen" placeholder="绿化率"></el-input>
    </el-form-item>
    <el-form-item label="规划户数" prop="buildFamilynum">
      <el-input v-model="dataForm.buildFamilynum" placeholder="规划户数"></el-input>
    </el-form-item>
    <el-form-item label="车位数量" prop="buildCarnum">
      <el-input v-model="dataForm.buildCarnum" placeholder="车位数量"></el-input>
    </el-form-item>
    <el-form-item label="物业类型" prop="realEstate">
      <el-input v-model="dataForm.realEstate" placeholder="物业类型"></el-input>
    </el-form-item>
    <el-form-item label="物业公司" prop="realEstateCompany">
      <el-input v-model="dataForm.realEstateCompany" placeholder="物业公司"></el-input>
    </el-form-item>
    <el-form-item label="物业费" prop="realEstateMoney">
      <el-input v-model="dataForm.realEstateMoney" placeholder="物业费"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          buildId: 0,
          areaId: '',
          buildName: '',
          buildPrice: '',
          buildAddress: '',
          buildSellAddress: '',
          buildStartTime: '',
          buildEndTime: '',
          buildSellTel: '',
          buildSellCard: '',
          developerId: '',
          areaAxis: '',
          buildSpecial: '',
          buildFitment: '',
          buildSellType: '',
          buildType: '',
          buildPng: '',
          buildVideo: '',
          buildVr: '',
          buildIntroduce: '',
          buildPropertyright: '',
          buildFloorspace: '',
          buildBuildspace: '',
          buildPlotratio: '',
          buildGreen: '',
          buildFamilynum: '',
          buildCarnum: '',
          realEstate: '',
          realEstateCompany: '',
          realEstateMoney: ''
        },
        dataRule: {
          areaId: [
            { required: true, message: '地区ID不能为空', trigger: 'blur' }
          ],
          buildName: [
            { required: true, message: '楼盘名称不能为空', trigger: 'blur' }
          ],
          buildPrice: [
            { required: true, message: '均价不能为空', trigger: 'blur' }
          ],
          buildAddress: [
            { required: true, message: '楼盘地址不能为空', trigger: 'blur' }
          ],
          buildSellAddress: [
            { required: true, message: '售楼处地址不能为空', trigger: 'blur' }
          ],
          buildStartTime: [
            { required: true, message: '开盘时间不能为空', trigger: 'blur' }
          ],
          buildEndTime: [
            { required: true, message: '交房时间不能为空', trigger: 'blur' }
          ],
          buildSellTel: [
            { required: true, message: '售楼电话不能为空', trigger: 'blur' }
          ],
          buildSellCard: [
            { required: true, message: '预售证号不能为空', trigger: 'blur' }
          ],
          developerId: [
            { required: true, message: '开发商ID不能为空', trigger: 'blur' }
          ],
          areaAxis: [
            { required: true, message: '地图坐标不能为空', trigger: 'blur' }
          ],
          buildSpecial: [
            { required: true, message: '是否优惠楼盘(0 - 否 1- 是)不能为空', trigger: 'blur' }
          ],
          buildFitment: [
            { required: true, message: '装修情况(  0 - 毛坯 1 - 简装 2 - 精装 3- 豪装)不能为空', trigger: 'blur' }
          ],
          buildSellType: [
            { required: true, message: '销售状态(0 - 在售 1- 新盘 2- 尾盘 3- 售罄 4-未开盘)不能为空', trigger: 'blur' }
          ],
          buildType: [
            { required: true, message: '楼盘类型(1-住宅 2-别墅 3-商铺 4-写字楼 5-公寓 6-底盘)不能为空', trigger: 'blur' }
          ],
          buildPng: [
            { required: true, message: '缩略图不能为空', trigger: 'blur' }
          ],
          buildVideo: [
            { required: true, message: '看房视频不能为空', trigger: 'blur' }
          ],
          buildVr: [
            { required: true, message: 'vr看房不能为空', trigger: 'blur' }
          ],
          buildIntroduce: [
            { required: true, message: '楼盘介绍不能为空', trigger: 'blur' }
          ],
          buildPropertyright: [
            { required: true, message: '产权年限不能为空', trigger: 'blur' }
          ],
          buildFloorspace: [
            { required: true, message: '占地面积不能为空', trigger: 'blur' }
          ],
          buildBuildspace: [
            { required: true, message: '建筑面积不能为空', trigger: 'blur' }
          ],
          buildPlotratio: [
            { required: true, message: '容积率不能为空', trigger: 'blur' }
          ],
          buildGreen: [
            { required: true, message: '绿化率不能为空', trigger: 'blur' }
          ],
          buildFamilynum: [
            { required: true, message: '规划户数不能为空', trigger: 'blur' }
          ],
          buildCarnum: [
            { required: true, message: '车位数量不能为空', trigger: 'blur' }
          ],
          realEstate: [
            { required: true, message: '物业类型不能为空', trigger: 'blur' }
          ],
          realEstateCompany: [
            { required: true, message: '物业公司不能为空', trigger: 'blur' }
          ],
          realEstateMoney: [
            { required: true, message: '物业费不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.buildId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.buildId) {
            this.$http({
              url: this.$http.adornUrl(`/building/build/info/${this.dataForm.buildId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.areaId = data.build.areaId
                this.dataForm.buildName = data.build.buildName
                this.dataForm.buildPrice = data.build.buildPrice
                this.dataForm.buildAddress = data.build.buildAddress
                this.dataForm.buildSellAddress = data.build.buildSellAddress
                this.dataForm.buildStartTime = data.build.buildStartTime
                this.dataForm.buildEndTime = data.build.buildEndTime
                this.dataForm.buildSellTel = data.build.buildSellTel
                this.dataForm.buildSellCard = data.build.buildSellCard
                this.dataForm.developerId = data.build.developerId
                this.dataForm.areaAxis = data.build.areaAxis
                this.dataForm.buildSpecial = data.build.buildSpecial
                this.dataForm.buildFitment = data.build.buildFitment
                this.dataForm.buildSellType = data.build.buildSellType
                this.dataForm.buildType = data.build.buildType
                this.dataForm.buildPng = data.build.buildPng
                this.dataForm.buildVideo = data.build.buildVideo
                this.dataForm.buildVr = data.build.buildVr
                this.dataForm.buildIntroduce = data.build.buildIntroduce
                this.dataForm.buildPropertyright = data.build.buildPropertyright
                this.dataForm.buildFloorspace = data.build.buildFloorspace
                this.dataForm.buildBuildspace = data.build.buildBuildspace
                this.dataForm.buildPlotratio = data.build.buildPlotratio
                this.dataForm.buildGreen = data.build.buildGreen
                this.dataForm.buildFamilynum = data.build.buildFamilynum
                this.dataForm.buildCarnum = data.build.buildCarnum
                this.dataForm.realEstate = data.build.realEstate
                this.dataForm.realEstateCompany = data.build.realEstateCompany
                this.dataForm.realEstateMoney = data.build.realEstateMoney
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/building/build/${!this.dataForm.buildId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'buildId': this.dataForm.buildId || undefined,
                'areaId': this.dataForm.areaId,
                'buildName': this.dataForm.buildName,
                'buildPrice': this.dataForm.buildPrice,
                'buildAddress': this.dataForm.buildAddress,
                'buildSellAddress': this.dataForm.buildSellAddress,
                'buildStartTime': this.dataForm.buildStartTime,
                'buildEndTime': this.dataForm.buildEndTime,
                'buildSellTel': this.dataForm.buildSellTel,
                'buildSellCard': this.dataForm.buildSellCard,
                'developerId': this.dataForm.developerId,
                'areaAxis': this.dataForm.areaAxis,
                'buildSpecial': this.dataForm.buildSpecial,
                'buildFitment': this.dataForm.buildFitment,
                'buildSellType': this.dataForm.buildSellType,
                'buildType': this.dataForm.buildType,
                'buildPng': this.dataForm.buildPng,
                'buildVideo': this.dataForm.buildVideo,
                'buildVr': this.dataForm.buildVr,
                'buildIntroduce': this.dataForm.buildIntroduce,
                'buildPropertyright': this.dataForm.buildPropertyright,
                'buildFloorspace': this.dataForm.buildFloorspace,
                'buildBuildspace': this.dataForm.buildBuildspace,
                'buildPlotratio': this.dataForm.buildPlotratio,
                'buildGreen': this.dataForm.buildGreen,
                'buildFamilynum': this.dataForm.buildFamilynum,
                'buildCarnum': this.dataForm.buildCarnum,
                'realEstate': this.dataForm.realEstate,
                'realEstateCompany': this.dataForm.realEstateCompany,
                'realEstateMoney': this.dataForm.realEstateMoney
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
